package cn.wolfcode.producer.api._02_send_mode;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

public class Producer {
    public static void main(String[] args) throws Exception {
        //1 创建一个生产者对象, 并且指定一个生产者组
        DefaultMQProducer producer = new DefaultMQProducer("api-producer-demo");
        //2 设置名字服务的地址
        producer.setNamesrvAddr("127.0.0.1:9876");
        //3 启动生产者
        producer.start();
        //4 创建一个消息
        for (int i = 0; i < 100; i++) {
            Message message = new Message("02-send-mode",  "好好好,rocketmq".getBytes("utf-8"));
            //5 发送消息
            SendResult sendResult = producer.send(message);
            System.out.println(sendResult.getMsgId());
            System.out.println(sendResult.getSendStatus());
        }


        //6 关闭连接
        producer.shutdown();
    }
}
